package com.lxu.config;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
public class DataSourceConfig {

    @Primary
    @ConfigurationProperties(prefix = "spring.datasource.ds1")
    @Bean("ds1Properties")
    public DataSourceProperties ds1Properties(){
        return  new DataSourceProperties();
    }

    @Primary
    @Bean("ds1Source")
    public DataSource ds1Source(@Qualifier("ds1Properties") DataSourceProperties dataSourceProperties){
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }

    @ConfigurationProperties(prefix = "spring.datasource.ds2")
    @Bean("ds2Properties")
    public DataSourceProperties ds2Properties(){
        return  new DataSourceProperties();
    }

    @Bean("ds2Source")
    public DataSource ds2Source(@Qualifier("ds2Properties") DataSourceProperties dataSourceProperties){
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }

    @ConfigurationProperties(prefix = "spring.datasource.ds3")
    @Bean("ds3Properties")
    public DataSourceProperties ds3Properties(){
        return  new DataSourceProperties();
    }

    @Bean("ds3Source")
    public DataSource ds3Source(@Qualifier("ds3Properties") DataSourceProperties dataSourceProperties){
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }

    @ConfigurationProperties(prefix = "spring.datasource.ds4")
    @Bean("ds4Properties")
    public DataSourceProperties ds4Properties(){
        return  new DataSourceProperties();
    }

    @Bean("ds4Source")
    public DataSource ds4Source(@Qualifier("ds4Properties") DataSourceProperties dataSourceProperties){
        return dataSourceProperties.initializeDataSourceBuilder().build();
    }
}
